package com.newgrand.annexserver.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.newgrand.annexcommon.constant.StatusConst;
import com.newgrand.annexserver.beans.Attachmentrecord;
import com.newgrand.annexserver.beans.Dbconfig;
import com.newgrand.annexserver.mapper.business.AttachmentrecordMapper;
import com.newgrand.annexserver.service.AttachmentrecordService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.apache.commons.lang3.tuple.Pair;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * <p>
 * 附件记录表 服务实现类
 * </p>
 *
 * @author minyang
 * @since 2019-09-04
 */
@Service
public class AttachmentrecordServiceImpl extends ServiceImpl<AttachmentrecordMapper, Attachmentrecord> implements AttachmentrecordService {

    @Autowired
    AttachmentrecordMapper attachmentrecordMapper;

    public Integer countAttachmentrecord(String asr_table, String asr_code, String asr_db, String sessionid) {
        Integer count = attachmentrecordMapper.selectCount(new EntityWrapper<Attachmentrecord>().eq("asr_table", asr_table).
                eq("asr_code", asr_code).eq("asr_db", asr_db).eq("sessionid", sessionid).
                eq("state", StatusConst.STATE_ENALBE));
        return count;
    }

    public Pair<Boolean, String> addAttachmentrecord(Attachmentrecord attachmentrecord) {
        attachmentrecord.setCreatetime(new Date());
        attachmentrecord.setState(StatusConst.STATE_ENALBE);
        attachmentrecordMapper.insert(attachmentrecord);
        return Pair.of(true, "");
    }


}
